home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 6 / FM Towns Free Software Collection 6.iso / t_os / helper / source / tiff.c < prev   
Encoding:
C/C++ Source or Header  |  1993-07-08  |  3.8 KB  |  168 lines

  1. #include    <stdio.h>
  2. #include    <stdlib.h>
  3. #include    <string.h>
  4. #include    <msdos.cf>
  5. #include    <egb.h>
  6. #include    <tifflib.h>
  7. #include    "graphic.h"
  8.  
  9. #define    TRUE    1
  10. #define    FALSE    0
  11. #define    ERR    (-1)
  12.  
  13. #define LOAD_BUF_SIZE    (64*1024)
  14. #define DATA_BUF_SIZE    (10*1024)
  15. #define    PALT_BUF_SIZE    (256*8+4)
  16.  
  17. extern    int    screen_flg;
  18. extern    char    work[];
  19.  
  20. static    FILE    *tiff_fp;
  21. static    int    tiff_mode;
  22. static    int     max_x,max_y;
  23.  
  24. static    int    TIFF_read_data(char *buf, int size )
  25. {
  26.     fread(buf,1,size,tiff_fp);
  27.     return 0 ;
  28. }
  29. static    int    TIFF_put_data(char *buf, int lofs, int lines ) 
  30. {
  31.     BLOCK    para;
  32.  
  33.     para.ptn = buf;
  34.     para.sel = getds();
  35.     para.x1 = 0;
  36.     para.x2 = max_x - 1;
  37.     para.y1 = lofs;
  38.     para.y2 = lofs + lines - 1;
  39.     if ( tiff_mode == 1 )
  40.         EGB_putBlockColor(work,0,(char *)¶);
  41.     else
  42.         EGB_putBlock(work,0,(char *)¶);
  43.     return 0 ;
  44. }
  45. int    TIFF_disp(char *file)
  46. {
  47.     char    *load_buf;
  48.     char    *data_buf;
  49.     char    *comp_buf;
  50.     char    *palt_buf;
  51.     int     d_line, comp, fill;
  52.     long    strip, clut, dw;
  53.     BLOCK   *save;
  54.  
  55.     if ( (tiff_fp = fopen(file,"rb")) == NULL )
  56.         return ERR;
  57.  
  58.     if ( (load_buf = (char *)malloc(LOAD_BUF_SIZE +
  59.                     DATA_BUF_SIZE +
  60.                     PALT_BUF_SIZE +
  61.                     DECOMP_WORK_SIZE)) == NULL ) {
  62.     fclose(tiff_fp);
  63.     return ERR;
  64.     }
  65.  
  66.     data_buf = load_buf + LOAD_BUF_SIZE;
  67.     palt_buf = data_buf + DATA_BUF_SIZE;
  68.     comp_buf = palt_buf + PALT_BUF_SIZE;
  69.  
  70.     fread(load_buf,1,LOAD_BUF_SIZE,tiff_fp);
  71.  
  72.     if ( TIFF_getHead(load_buf,LOAD_BUF_SIZE) < 0 ||
  73.          (tiff_mode = TIFF_checkMode(&max_x,&max_y,&comp,
  74.                      &fill,&strip,&clut)) < 0 ||
  75.      tiff_mode == 24 )
  76.         goto ERROR;
  77.  
  78.     TIFF_setLoadFunc(TIFF_put_data,TIFF_read_data) ;
  79.  
  80.     /* 画面モードの設定 */
  81.  
  82.     MOS_disp(OFF);
  83.     if ( screen_flg == FALSE )
  84.     save = DSP_push_vram(0,0,639,479);
  85.     EGB_displayPage(work,0,0);
  86.     EGB_writePage(work,0);
  87.     EGB_color(work,1,0);
  88.     EGB_clearScreen(work);
  89.     EGB_displayPage(work,0,1);
  90.  
  91.     switch(tiff_mode) {
  92.     case 1:     /* 2値 */
  93.         EGB_resolution(work,0,3);
  94.     EGB_writePage(work,0);
  95.         EGB_color(work,0,0) ;
  96.     EGB_color(work,1,15);
  97.     EGB_clearScreen(work);
  98.     break;
  99.  
  100.     case 4:     /* 16色 */
  101.         EGB_resolution(work,0,3);
  102.     EGB_writePage(work,0);
  103.     EGB_color(work,1,0);
  104.     EGB_clearScreen(work);
  105.         break ;
  106.  
  107.     case 8:     /* 256色 */
  108.         EGB_resolution(work,0,12);
  109.     EGB_writePage(work,0);
  110.     EGB_color(work,1,0);
  111.     EGB_clearScreen(work);
  112.         break ;
  113.  
  114.     case 16:    /* 32K色 */
  115.         if ( max_x > 320 ) { /* 高解像度モード */
  116.             EGB_resolution(work,0,17);
  117.             EGB_displayStart(work,3,512,480);
  118.         } else {
  119.             EGB_resolution(work,0,10);
  120.             EGB_displayStart(work,2,2,2);
  121.             EGB_displayStart(work,3,320,240);
  122.         }
  123.     EGB_color(work,1,0);
  124.     EGB_clearScreen(work);
  125.         break ;
  126.     }
  127.  
  128.     dw = max_x;
  129.     if ( tiff_mode == 4 && (dw & 7) != 0 )
  130.        dw += 8 - (dw & 7) ;
  131.     d_line = DATA_BUF_SIZE / ((dw * tiff_mode + 7) / 8);
  132.  
  133.     if ( clut != 0 ) {
  134.         TIFF_getPal(palt_buf) ;
  135.         EGB_palette(work,0,palt_buf) ;
  136.     }
  137.  
  138.     TIFF_loadImage(tiff_mode,max_x,max_y,strip,fill,
  139.            comp,data_buf,dw,d_line,comp_buf);
  140.  
  141.     mos_wait();
  142.  
  143.     EGB_displayPage(work,0,0);
  144.     EGB_resolution(work,0,3);
  145.     EGB_resolution(work,1,3);
  146.     EGB_writePage(work,1);
  147.     DSP_palette();
  148.     EGB_clearScreen(work);
  149.     EGB_writePage(work,0);
  150.     DSP_palette();
  151.     EGB_clearScreen(work);
  152.  
  153.     if ( screen_flg == FALSE )
  154.     DSP_pop_vram(save);
  155.  
  156.     EGB_displayPage(work,0,3);
  157.     MOS_disp(ON);
  158.  
  159.     free(load_buf);
  160.     fclose(tiff_fp);
  161.     return FALSE;
  162.  
  163. ERROR:
  164.     free(load_buf);
  165.     fclose(tiff_fp);
  166.     return ERR;
  167. }
  168.